#pragma once

#include <QMainWindow>
#include <QSerialPort>

QT_BEGIN_NAMESPACE
class QComboBox;
class QPushButton;
class QTextEdit;
class QLineEdit;
QT_END_NAMESPACE

class QtWidgetApplication : public QMainWindow
{
    Q_OBJECT

public:
    QtWidgetApplication(QWidget *parent = nullptr);
    ~QtWidgetApplication();

private slots:
    void openSerialPort();
    void closeSerialPort();
    void writeData();
    void readData();
    void handleError(QSerialPort::SerialPortError error);

private:
    void initActionsConnections();
    void initSerialPortSettings();

    QSerialPort *m_serial = nullptr;
    
    // UI elements
    QComboBox *m_serialPortComboBox = nullptr;
    QComboBox *m_baudRateComboBox = nullptr;
    QComboBox *m_dataBitsComboBox = nullptr;
    QComboBox *m_parityComboBox = nullptr;
    QComboBox *m_stopBitsComboBox = nullptr;
    QComboBox *m_flowControlComboBox = nullptr;
    QPushButton *m_openButton = nullptr;
    QPushButton *m_closeButton = nullptr;
    QPushButton *m_sendButton = nullptr;
    QTextEdit *m_receiveTextEdit = nullptr;
    QTextEdit *m_sendTextEdit = nullptr;
};

